﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using SortWithTemplate;
using System.Collections.ObjectModel;

namespace UnitTests
{
    [TestFixture]
    class TestSortWithTemplate
    {
        static PersonsTemplate TestPersonList;

        [SetUp]
        public static void Init()
        {
            Collection<PersonTemplate> TempPersonList = new Collection<PersonTemplate>();
            TempPersonList.Add(new PersonTemplate(123, "A", "AA", 3));
            TempPersonList.Add(new PersonTemplate(128, "B", "BB", 1));
            TempPersonList.Add(new PersonTemplate(223, "D", "DD", 5));
            TempPersonList.Add(new PersonTemplate(119, "C", "CC", 8));
            TempPersonList.Add(new PersonTemplate(133, "E", "EE", 4));
            TestPersonList = new PersonsTemplate(TempPersonList);
        }

        [Test]
        public static void TestSortByCode()
        {
            TestPersonList.Sort("Code");

            Collection<PersonTemplate> expected = new Collection<PersonTemplate>();
            expected.Add(new PersonTemplate(119, "C", "CC", 8));
            expected.Add(new PersonTemplate(123, "A", "AA", 3));
            expected.Add(new PersonTemplate(128, "B", "BB", 1));
            expected.Add(new PersonTemplate(133, "E", "EE", 4));
            expected.Add(new PersonTemplate(223, "D", "DD", 5));

            Assert.True(TestPersonList.Compare(expected));
        }

        [Test]
        public static void TestSortByAge()
        {
            TestPersonList.Sort("Age");

            Collection<PersonTemplate> expected = new Collection<PersonTemplate>();
            expected.Add(new PersonTemplate(128, "B", "BB", 1));
            expected.Add(new PersonTemplate(123, "A", "AA", 3));
            expected.Add(new PersonTemplate(133, "E", "EE", 4));
            expected.Add(new PersonTemplate(223, "D", "DD", 5));
            expected.Add(new PersonTemplate(119, "C", "CC", 8));

            Assert.True(TestPersonList.Compare(expected));
        }

        [Test]
        public static void TestSortByFirstName()
        {
            TestPersonList.Sort("FirstName");

            Collection<PersonTemplate> expected = new Collection<PersonTemplate>();
            expected.Add(new PersonTemplate(123, "A", "AA", 3));
            expected.Add(new PersonTemplate(128, "B", "BB", 1));
            expected.Add(new PersonTemplate(119, "C", "CC", 8));
            expected.Add(new PersonTemplate(223, "D", "DD", 5));
            expected.Add(new PersonTemplate(133, "E", "EE", 4));

            Assert.True(TestPersonList.Compare(expected));
        }

        [Test]
        public static void TestSortByLastName()
        {
            TestPersonList.Sort("LastName");

            Collection<PersonTemplate> expected = new Collection<PersonTemplate>();
            expected.Add(new PersonTemplate(123, "A", "AA", 3));
            expected.Add(new PersonTemplate(128, "B", "BB", 1));
            expected.Add(new PersonTemplate(119, "C", "CC", 8));
            expected.Add(new PersonTemplate(223, "D", "DD", 5));
            expected.Add(new PersonTemplate(133, "E", "EE", 4));

            Assert.True(TestPersonList.Compare(expected));
        }

    }
}
